package com.fuzhixuan.springcloud.controller;

import com.fuzhixuan.cloud.entities.CommonResult;
import com.fuzhixuan.cloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName ConsumerController
 * @Author fuzhixuan
 * @Date 2022/3/8 16:09
 */
@RestController
@Slf4j
public class ConsumerController {
    public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE";

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/consumer/getPaymentById")
    public CommonResult<Payment> getPaymentById(Integer id) {
        return restTemplate.getForObject(PAYMENT_URL + "/user-api/payment/getById?id=" + id, CommonResult.class);
    }

    @PostMapping("/consumer/createPayment")
    public CommonResult createPayment(@RequestBody Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "/user-api/payment/insert", payment, CommonResult.class);
    }
}
